﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EmoneyWeiXinBLL;
using EmoneyWeiXinEntity;
using EmoneyWeiXinCommon;
using System.Data;
namespace EmoneyWeiXin.Controllers
{
    public class ReplyManagerController : Controller
    {
        //
        // GET: /ReplyManager/

        public ActionResult Index()
        {
            ViewBag.leftid = int.Parse(Request["leftid"]);
            return View();
        }
        //查询操作
        public ActionResult GetReplyManager()
        {
            var strJson1 = "";

            int weixinid = int.Parse(Request["weixinid"]);
            int hisid = int.Parse(Request["hisid"]);
            var list = ReplyManagerBLL.getReplyManagerList(weixinid, hisid);

            if (list != null && list.Count > 0)
            {
                var obj = list[0];
                //strJson1 = JsonTools.ToJson(obj);
                var ds = ReplyManagerBLL.getReplyManager_NewsReport_ListByID(obj.id);

                DataTable dt = null;
                if (ds != null && ds.Tables.Count > 0)
                {
                    //strJson2 = JsonTools.ToJson(ds.Tables[0]);
                    dt = ds.Tables[0];
                }
                strJson1 = JsonTools.ToJson(new { obj1 = obj, obj2 = dt });
            }
            return Content( strJson1);
            // return strJson1 + "" + strJson2;
        }
        //更新回复内容
        [ValidateInput(false)]
        public string UpdateReplyManager()
        {
            var ire = 0;
            int weixinid = int.Parse(Request["weixinid"]);
            int id = int.Parse(Request["id"]);
            int op = int.Parse(Request["op"]);
            var newsreportids = Request["newsreportids"];
            if (op == -1)
            {
                ire = ReplyManagerBLL.DeleteReplyManager(id);
            }
            else
            {
                int hisid = int.Parse((Request["hisid"] == null || Request["hisid"] == "") ? "1" : Request["hisid"]);
                string content = Request["content"];
                ReplyManagerEntity entity = new ReplyManagerEntity();
                entity.id = id;
                entity.CONTENT = content;
                entity.createtime = DateTime.Now;
                entity.updatetime = DateTime.Now;
                entity.remark = "";
                entity.hisid = hisid;
                entity.weixinid = weixinid;
                ire = ReplyManagerBLL.UpdateReplyManager(entity, newsreportids.Trim('^'));
            }
            if (ire > 0)
            {
                return "1";
            }
            else
            {
                return "";
            }
        }
    }
}
